CC=gcc
SOURCES=main.c init.c abort.c pipes.c child.c exec.c
OBJFILES=main.o init.o abort.o pipes.o child.o exec.o
BIN=osd_server
CFLAGS=-c -Wall
LDFAGS=-lc
INSTALL_PATH=/usr/local/bin

all: osd_cat all_objects
	$(CC) -o $(BIN) $(OBJFILES) $(LDFAGS)

osd_cat:
	whatis osd_cat &>/dev/null; \
	if [ "$$?" -ne "0" ]; then \
		echo 'Error: osd_cat utility is not installed!'; \
		echo 'Install it first (xosd package)!'; \
		exit 1; \
	fi \

all_objects: $(SOURCES)
	$(CC) $(CFLAGS) $(SOURCES)

.PHONY: clean
clean:
	rm -f $(BIN) \
		$(OBJFILES)

.PHONY: install
install: $(BIN)
	install -m 755 $(BIN) $(INSTALL_PATH)

.PHONY: uninstall
uninstall:
	rm -f $(INSTALL_PATH)/$(BIN)

